#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/uio.h>

static inline int
ink_socket(int domain, int type, int protocol)
{
	int sockfd = socket(domain, type, protocol);
	if(sockfd == -1)
	{
		perror("socket");
		abort();
	}
	return sockfd;
}

static inline void
ink_bind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
{
	int ret = bind(sockfd, my_addr, addrlen);
	if(ret < 0)
	{
		perror("bind");
		abort();
	}
}

static inline void
ink_listen(int sockfd, int backlog)
{
	int ret = listen(sockfd, backlog);
	if(ret < 0)
	{
		perror("listen");
		abort();
	}
}

static inline void
ink_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen)
{
	int ret = getsockopt(sockfd, level, optname, optval, optlen);
	if(ret < 0)
	{
		perror("getsockopt");
		abort();
	}
}

static inline void
ink_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen)
{
	int ret = setsockopt(sockfd, level, optname, optval, optlen);
	if(ret < 0)
	{
		perror("setsockopt");
		abort();
	}
}

int ink_fcntl(int fd, int cmd, int arg);
int ink_set_fcntl(int fd, int arg);
int ink_clr_fcntl(int fd, int arg);
int ink_set_nonblock(int fd);
int ink_set_blocking(int fd);
int ink_set_close_exec(int fd);
int ink_clr_close_exec(int fd);


int64_t ink_readv(int fd, struct iovec *vector, size_t count);
int64_t ink_read(int fd, void *buff, size_t count);
int64_t ink_writev(int fd, struct iovec *vector, size_t count);
int64_t ink_write(int fd, void *buff, size_t count);
